$(document).ready(function(){
	initAreaData('area1',-1);
	
	$('#area1').off('change').on('change',function(){
		var parentCode=$(this).val();
		initAreaData('area2',parentCode);
	});
	$('#area2').off('change').on('change',function(){
		var parentCode=$(this).val();
		initAreaData('area3',parentCode);
	});
	
	function initAreaData(selectId,parentCode){
		$.ajax({
			type:'post',
			data:{"parentCode":parentCode},//Json
			url:'address/list',
			success:function(areaList){
				//console.log(areaList);
				var options='';
				$.each(areaList,function(index,area){
					//console.log(index);
					//console.log(area);
					//console.log(area.areaCode+"\t"+area.areaName);
					var areaCode=area.areaCode;
					var areaName=area.areaName;
					options+='<option value="'+areaCode+'">'+areaName+'</option>';
				});
				//console.log(options);
				$('#'+selectId).html(options);
				$('#'+selectId).change();
			}
			
		});
	}
});